package com.ldn.basic.enumeration;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 李大牛家的牛 (scafel@163.com)
 * @createDate 2024/8/15 - 21:21
 * @description ...
 **/
@Schema(description = "删除类型枚举")
@Getter
public enum DeleteMethodEnum {


    // 后台删除
    ADMIN("ADMIN", "后台删除"),
    // 用户删除
    USER("USER", "用户删除"),
    // 未知删除
    UNKNOWN("UNKNOWN", "未知删除"),
    ;


    private static final Map<String, DeleteMethodEnum> codeToEnumMap = new HashMap<>();

    static {
        for (DeleteMethodEnum type : DeleteMethodEnum.values()) {
            codeToEnumMap.put(type.getCode(), type);
        }
    }

    private final String code;
    /**
     * 自定义描述
     **/
    private final String message;

    DeleteMethodEnum(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static DeleteMethodEnum getType(String code) {
        DeleteMethodEnum type = codeToEnumMap.get(code.toUpperCase());
        if (type == null) {
            return DeleteMethodEnum.UNKNOWN;
        }
        return type;
    }
}
